<? include ("../init.php") ?>
<? include ("../includes/class.upload.php") ?>
<?
  $product_set_id = $_POST['product_set_id'];
  $catalogue = addslashes($_POST['catalogue']);
  $setname = addslashes($_POST['name']);
  
  $img_sql = '';
  
  if(isset($_FILES["product_set_img"]) && is_uploaded_file($_FILES["product_set_img"]["tmp_name"]) && $_FILES["product_set_img"]["tmp_name"]!=''){
    //$image = new image();
    //
    //ini_set("html_errors", "0");
    //
    //// Check the upload
    //if ($_FILES["product_set_img"]["error"] != 0) {
    //  echo "ERROR:invalid upload";
    //  exit(0);
    //}
    //
    //$name = get_file_name($product_set_id, $_FILES['product_set_img']['tmp_name']);
    //$path = "../../images/products/set/".$product_set_id;
    //$urlpath = get_url_path($path);
    //$link = URL."/".$urlpath."/".$name;
    //$filename = $path ."/". $name;
    //
    //if(!file_exists($path)){
    //  mkdir($path);
    //}
    //
    //if (!move_uploaded_file($_FILES['product_set_img']['tmp_name'], $filename)){
    //  echo 'Problem: Could not move file to destination directory';
    //  exit(0);
    //}
    //
    //ini_set('memory_limit', '100M');
    //$image->load($filename);
    //$image->resize(350,260);
    //$image->save($filename);
    //ini_set('memory_limit', '16M');
    //
    //chmod($filename,0755);
    //
    ////$sql = "UPDATE products SET product_set_img ='$name' WHERE product_set_id=$product_set_id";
    ////$db->execute($sql);
    //
    //if(file_exists($path.'/'.$_POST['old_img']) && trim($_POST['old_img'])!=''){
    //  unlink($path.'/'.$_POST['old_img']);
    //}
    //$img_sql = ",product_set_img='$name'";
    ////echo $img_sql;
    
    
  
    $handle = new Upload($_FILES['product_set_img']);
    if ($handle->uploaded)
    {
      $handle->image_resize = true;
      $handle->image_ratio_fill = true;
      $handle->image_x = 350;
      $handle->image_y = 260;
      $handle->Process('../../images/products/set/'.$product_set_id);
      
      if ($handle->processed)
      {
        @unlink('../../images/products/set/'.$product_set_id.'/'.$_POST['old_img']);
        $img_sql = ' ,product_set_img="'.$handle->file_dst_name.'" ';
      }
      $handle->clean();
    }
  }
  
  $sql = "UPDATE product_set SET
    product_cat_id='$catalogue',
    product_set_name='$setname'
    $img_sql
    WHERE product_set_id=$product_set_id";
  $db->execute($sql);
  
  header("Location:index.php");
?>